<template>
  <div id="app">
    <!-- 头部直通车 -->
    <Topbar :key="topBarKeyValue"></Topbar>
    <!-- 页头的标题 -->
    <Header></Header>
    <router-view @fn="reloadTopBar" />
    <!-- 页脚 -->
    <Footer></Footer>
    <!-- 登录模态框 -->
    <Login v-show="isShowLoginModal"></Login>

    <!-- 提示框组件的调用 -->
    <transition name="fade">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>


<script>
import Topbar from "@/components/Topbar";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
import Login from "@/components/Login";
import Toast from "@/components/Toast";
import { mapState } from "vuex";

export default {
  data() {
    return { topBarKeyValue: 1 };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  methods: {
    reloadTopBar() {
      this.topBarKeyValue++;
    },
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.ShowLoginModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          //两个值不相等说明切换了
          //就可以让topBarKeyValue发生变化
          //即组件就重载了
          this.topBarKeyValue++;
        }
      },
    },
  },
};
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
// 定义进入过渡的开始状态==离场的结束状态
.fade-enter,
.fade-leave-to {
  opacity: 0;
}

//定义过渡属性
.fade-enter-active,
.fade-leave-active {
  transition: all 0.3s linear;
}
//定义进入过渡的结束状态==离场的初始状态
.fade-enter-to,
.fade-leave {
  opacity: 1;
}
</style>
